/*
 * @Author: szx
 * @Date: 2022-04-09 13:06:54
 * @LastEditTime: 2022-04-09 13:15:28
 * @Description: 
 * @FilePath: \leetcode\剑指offerII\042\042.js
 */
var RecentCounter = function () {
    this.nums = [];
    this.last = 0;
};

/** 
 * @param {number} t
 * @return {number}
 */
RecentCounter.prototype.ping = function (t) {
    const nums = this.nums;
    nums.push(t);
    while (nums[this.last] < t - 3000) {
        this.last++;
    }
    // console.log(nums.length, this.last)
    return nums.length - this.last;
};

/**
 * Your RecentCounter object will be instantiated and called as such:
 * var obj = new RecentCounter()
 * var param_1 = obj.ping(t)
 */
var obj = new RecentCounter()
console.log(obj.ping(1))
console.log(obj.ping(100))
console.log(obj.ping(3001))
console.log(obj.ping(3002))